package com.peak.spring.boot.tools;

import java.util.Collection;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

public class Emptys {

	/**
	 * 判断是否为空.
	 */
	public static boolean isEmpty(Object obj) {
		if (obj instanceof String) {
			return StringUtils.isBlank(Converts.toString(obj));
		}
		return obj == null;
	}

	/**
	 * 判断是否不为空.
	 */
	public static boolean isNotEmpty(Object obj) {
		return !isEmpty(obj);
	}

	/**
	 * 判断是否为空.
	 */
	public static boolean isEmpty(Collection<?> collection) {
		return (collection == null) || collection.isEmpty();
	}

	/**
	 * 判断数组成员内部的值是否为空
	 * 
	 * @param obj
	 * @return
	 */
	public static boolean isMemberEmpty(Object... obj) {
		if (obj == null) {
			return true;
		}
		boolean flag = false;
		for (Object object : obj) {
			if (object instanceof String) {
				flag = StringUtils.isBlank(Converts.toString(object));
			} else {
				flag = object == null;
			}
			if (flag) {
				break;
			}
		}
		return flag;
	}

	/**
	 * 判断是否不为空.
	 */
	public static boolean isNotEmpty(Collection<?> collection) {
		return !isEmpty(collection);
	}

	/**
	 * 判断是否为空.
	 */
	public static boolean isEmpty(Map<?, ?> map) {
		return (map == null) || map.isEmpty();
	}

	/**
	 * 判断是否不为空.
	 */
	public static boolean isNotEmpty(Map<?, ?> map) {
		return !isEmpty(map);
	}

	/**
	 * 判断是否为空.
	 */
	public static boolean isEmpty(Object[] array) {
		return (array == null) || array.length <= 0;
	}

	/**
	 * 判断是否不为空.
	 */
	public static boolean isNotEmpty(Object[] array) {
		return !isEmpty(array);
	}

	/**
	 * 判断成员内部是否不为空
	 * 
	 * @param obj
	 * @return
	 */
	public static boolean isNotMemberEmpty(Object... obj) {
		return !isMemberEmpty(obj);
	}

}
